package com.yjc.dp;

import java.util.Arrays;

/**
 * 121. 买卖股票的最佳时机
 *
 * @author yjc
 * @create 2024-07-22 10:15
 */
public class Subject_4 {
    public static void main(String[] args) {
        int[] prices = {7, 6, 4, 3, 1};
        int n = prices.length;

        int[] dp = new int[n];
        dp[0] = 0;//第一天无利润

        for (int i = 1; i < n; i++) {
            dp[i] = prices[i] - prices[i - 1];//获取利润
            prices[i] = Integer.min(prices[i], prices[i - 1]);//把更小的股票后移
        }
        int res = Arrays.stream(dp).max().getAsInt();//取最大利润
        System.out.println(res);
    }
}
